﻿/*
Copyright (c) 2008 William Duff

Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights 
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all 
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.Text;

namespace LiveUpload.Facebook
{
    public class Album
    {
        #region Constructors

        /// <summary>
        /// Constructs an Album object to represent an uncreated Facebook photo album.
        /// </summary>
        public Album(string name, string location, string description)
            : this(string.Empty, string.Empty, string.Empty, name, 0d, 0d, location, 
                description, string.Empty, 0, string.Empty)
        {
        }

        /// <summary>
        /// Constructs an Album object to represent an uncreated Facebook photo album.
        /// </summary>
        public Album(string name, string location, string description, string visible) 
            : this(string.Empty, string.Empty, string.Empty, name, 0d, 0d, location, 
                description, string.Empty, 0, visible)
        {
        }

        /// <summary>
        /// Constructs an Album object to represent a Facebook photo album.
        /// </summary>
        public Album(string id, string coverId, string ownerId, string name, 
            double createdUnixTimestamp, double modifiedUnixTimestamp, string location, 
            string description, string link, int size, string visible)
        {
            this.id = id;
            this.coverId = coverId;
            this.ownerId = ownerId;
            this.name = name;
            this.created = FacebookParser.ConvertFromUnixTimestamp(createdUnixTimestamp);
            this.createdUnixTimestamp = createdUnixTimestamp;
            this.modified = FacebookParser.ConvertFromUnixTimestamp(modifiedUnixTimestamp);
            this.modifiedUnixTimestamp = modifiedUnixTimestamp;
            this.location = location;
            this.description = description;
            this.link = link;
            this.size = size;
            this.visible = visible;
        }

        #endregion

        #region Private Fields

        private string id;
        private string coverId;
        private string ownerId;
        private string name;
        private DateTime? created;
        private double createdUnixTimestamp;
        private DateTime? modified;
        private double modifiedUnixTimestamp;
        private string location;
        private string description;
        private string link;
        private int size;
        private Photo coverPhoto;
        private string visible;

        #endregion

        #region Public Fields

        /// <summary>
        /// A unique identifier for the album.
        /// </summary>
        public string Id
        {
            get { return this.id; }
            set { this.id = value; }
        }

        /// <summary>
        /// The id of the photo used as the cover for the album.
        /// </summary>
        public string CoverPhotoId
        {
            get { return this.coverId; }
            set { this.coverId = value; }
        }

        /// <summary>
        /// The user id of the owner of the album.
        /// </summary>
        public string OwnerId
        {
            get { return this.ownerId; }
            set { this.ownerId = value; }
        }

        /// <summary>
        /// The name of the album.
        /// </summary>
        public string Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        /// <summary>
        /// The date the album was created. Null means it has not been created yet.
        /// </summary>
        public DateTime? Created
        {
            get { return this.created; }
            set { this.created = value; }
        }

        /// <summary>
        /// The date the album was created in Unix time. Zero means it has not been created yet.
        /// </summary>
        public double CreatedUnixTimestamp
        {
            get { return this.createdUnixTimestamp; }
            set { this.createdUnixTimestamp = value; }
        }

        /// <summary>
        /// The date the album was last updated. Null means never.
        /// </summary>
        public DateTime? Modified
        {
            get { return this.modified; }
            set { this.modified = value; }
        }

        /// <summary>
        /// The date the album was last updated in Unix time. Zero means never.
        /// </summary>
        public double ModifiedUnixTimestamp
        {
            get { return this.modifiedUnixTimestamp; }
            set { this.modifiedUnixTimestamp = value; }
        }

        /// <summary>
        /// The location for the album.
        /// </summary>
        public string Location
        {
            get { return this.location; }
            set { this.location = value; }
        }

        /// <summary>
        /// The description of the album.
        /// </summary>
        public string Description
        {
            get { return this.description; }
            set { this.description = value; }
        }

        /// <summary>
        /// The URL to the album.
        /// </summary>
        public string Link
        {
            get { return this.link; }
            set { this.link = value; }
        }

        /// <summary>
        /// The number of photos in the album.
        /// </summary>
        public int Size
        {
            get { return this.size; }
            set { this.size = value; }
        }

        /// <summary>
        /// The photo that is shown as the cover of the album.
        /// </summary>
        public Photo CoverPhoto
        {
            get { return this.coverPhoto; }
            set { this.coverPhoto = value; }
        }

        /// <summary>
        /// Who the album is visible to. Should be one of "friends", "friends-of-friends", 
        /// "networks", "everyone" or empty.
        /// </summary>
        public string Visible
        {
            get { return this.visible; }
            set { this.visible = value; }
        }


        #endregion

        #region Public Methods

        /// <summary>
        /// Checks if the album has been created.
        /// </summary>
        /// <returns>
        /// true if the album has been created and false otherwise.
        /// </returns>
        public bool IsCreated()
        {
            return this.created.HasValue;
        }

        /// <summary>
        /// Generic equality function.
        /// </summary>
        /// <param name="obj">
        /// An object to compare equality with.
        /// </param>
        /// <returns>
        /// true if this is equal to the given object and false otherwise.
        /// </returns>
        public override bool Equals(object obj)
        {
            return this == obj as Album;
        }

        /// <summary>
        /// Checks for reference or value equality.
        /// </summary>
        /// <param name="left">
        /// The left hand side of the operator.
        /// </param>
        /// <param name="right">
        /// The right hand side of the operator.
        /// </param>
        /// <returns>
        /// true if the Albums are equal and false otherwise.
        /// </returns>
        public static bool operator ==(Album left, Album right)
        {
            if (object.ReferenceEquals(left, right))
            {
                return true;
            }
            else if (left is Album && right is Album)
            {
                return left.Id == right.Id;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Checks for reference or value inequality.
        /// </summary>
        /// <param name="left">
        /// The left hand side of the operator.
        /// </param>
        /// <param name="right">
        /// The right hand side of the operator.
        /// </param>
        /// <returns>
        /// true if the Albums are not equal and false otherwise.
        /// </returns>
        public static bool operator !=(Album left, Album right)
        {
            return !(left == right);
        }

        /// <summary>
        /// Serves as a hash function for Album.
        /// </summary>
        /// <returns>
        /// A hash code.
        /// </returns>
        public override int GetHashCode()
        {
            return this.id.GetHashCode();
        }

        #endregion
    }
}
